package myjava.lang.reflect.proxy;

public class Demo {

    public static void main(String[] args) {
        DemoService service = new ReflectionHandler(new MyDemoServiceImpl()).getProxy();
        String str1 = service.serviceTest();
        System.out.println("serviceTest="+str1);
        String str2 = service.otherMethod();
        System.out.println("otherMethod="+str2);

        for(int i=0; i<10; i++){
            System.out.println(i+"<<2="+(i<<2));
        }

        int allow_select = 1 << 0; // 0001
        int allow_insert = 1 << 1; // 0010
        int allow_update = 1 << 2; // 0100
        int allow_delete = 1 << 3; // 1000

        //或（ | ）每一位进行比较，两位有一位是1，结果就是1（-4 | 1 = -3）
        int permission1 = allow_select | allow_insert | allow_update | allow_delete;
        System.out.println(Integer.toBinaryString(permission1));

        //与（ & ）每一位进行比较，两位都为1，结果为1，否则为0（-4 & 1 = 0）
        int permission2 = allow_select & permission1;
        System.out.println(permission2+"="+Integer.toBinaryString(permission2));

        //非（ ~ ） 每一位进行比较，按位取反（符号位也要取反）（~ -4 = 3）
        System.out.println(Integer.toBinaryString(~allow_select));

        int num = Integer.parseInt("101" , 2);
        System.out.println("num="+num);


        System.out.println("----->>>>>>");
        int num1 = 12;
        System.out.println("num1="+num1+";bina="+Integer.toBinaryString(num1));
        int num2 = num1 >>>1;
        System.out.println("num2="+num2+";bina="+Integer.toBinaryString(num2));
        int num3 = num1 | num2;
        System.out.println("num3="+num3+";bina="+Integer.toBinaryString(num3));

        System.out.println("tableSizeFor---->>>"+tableSizeFor(17));
    }
    public static final int tableSizeFor(int cap) {
        int n = cap - 1;
        n |= n >>> 1;
        n |= n >>> 2;
        n |= n >>> 4;
        n |= n >>> 8;
        n |= n >>> 16;
        return (n < 0) ? 1 : (n >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : n + 1;
    }

}
